#define _CRT_SECURE_NO_WARNINGS

class Solution {
public:
    int minCostClimbingStairs(vector<int>& cost) {
        if (cost.size() == 1 || cost.size() == 2)
            return min(cost[0], cost[1]);

        vector<int> dp({ 0, 0 });
        cost.push_back(0);
        int length = cost.size();
        for (int i = 2; i < length; i++)
        {
            int push = min(cost[i - 1] + dp[1], cost[i - 2] + dp[0]);
            dp[0] = dp[1];
            dp[1] = push;
        }

        return dp[1];
    }
};